package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/5.
 */
@HttpInlet(Conn.SHOW_CLASS_LIST)
public class ShowTypeListGet extends BaseAsyGet<ShowTypeListGet.ShowTypeEntityList> {

    public ShowTypeListGet(AsyCallBack<ShowTypeEntityList> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected ShowTypeEntityList parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            ShowTypeEntityList showTypeEntityList = new ShowTypeEntityList();

            JSONArray array = object.optJSONArray("data");

            for (int i = 0; i < array.length(); i++) {

                JSONObject entityObject = array.optJSONObject(i);

                ShowTypeEntity showTypeEntity = new ShowTypeEntity();

                showTypeEntity.id = entityObject.optString("id");
                showTypeEntity.title = entityObject.optString("title");

                showTypeEntityList.showTypeEntityList.add(showTypeEntity);

            }

            return showTypeEntityList;

        }


        return null;
    }

    public static class ShowTypeEntityList{

        public List<ShowTypeEntity> showTypeEntityList = new ArrayList<>();
    }

    public static class ShowTypeEntity{

        public String id, title;

    }
}
